package day27;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.util.Scanner;

public class HomeWork {}

class User implements Serializable{
    Integer id;
    String name;
    public User(Integer id, String name){
        this.id = id;
        this.name = name;
    }
}

class Server4{
    public static void main(String[] args)  throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        Socket s = ss.accept();
        OutputStream os= s.getOutputStream();
        ObjectOutputStream oos= new ObjectOutputStream(os);
        User user = new User(1, "Jack");
        oos.writeObject(user);
        s.getInputStream();
        oos.close();
    }
}

class Client4{
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Socket client = new Socket("192.168.9.158",9999);
            InputStream is = client.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);
            User user = (User) ois.readObject();
            System.out.println(user.id+" "+user.name);
    }
}

class Server5{
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ServerSocket ss = new ServerSocket(9999);
        Socket s = ss.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        OutputStream os = s.getOutputStream();
        String str = br.readLine();
        System.out.println(str);
        String[] strs =  str.split(" ");
        double result = 0;
        try {
            switch (strs[0]) {
                case "ADD":
                    result = Double.parseDouble(strs[1]) + Double.parseDouble(strs[2]);
                    break;
                case "SUB":
                    result = Double.parseDouble(strs[1]) - Double.parseDouble(strs[2]);
                    break;
                case "MUL":
                    result = Double.parseDouble(strs[1]) * Double.parseDouble(strs[2]);
                    break;
                case "DIV":
                    if (Double.parseDouble(strs[2]) != 0) {
                        result = Double.parseDouble(strs[1]) / Double.parseDouble(strs[2]);
                    } else {
                        System.out.println("输入错误！！！");
                    }
                    break;
                default:
                    System.out.println("未知符号！！！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println(result);
        os.write((result+"\n").getBytes());
    }
}

class Client5{
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Scanner sc = new Scanner(System.in);
        Socket s = new Socket("192.168.9.158",9999);
        OutputStream bw = s.getOutputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String str = sc.nextLine();
        //写
        bw.write((str+"\n").getBytes());
        //读
        String result = br.readLine();
        System.out.println(result);
    }
}